using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AjaxControlToolkit;
using MTRC.ODMS.Web.SOM.AdmissionRegistry;

namespace MTRC.ODMS.Web.SOM.Popup
{
    /// <summary>
    /// author:Nearly
    /// </summary>
    public partial class popupSearchWork : BasePage_SOM
    {
        #region  Page Load and UnLoad
        private string tnNo
        {
            get
            {
                return ViewState["tnNo"].ToString();
            }
            set
            {
                ViewState["tnNo"] = value;
            }
        }
        private string transNo
        {
            get
            {
                return ViewState["transNo"].ToString();
            }
            set
            {
                ViewState["transNo"] = value;
            }
        }
        //remove by gordon 20151022 U247
        //private string StationID
        //{
        //    get
        //    {
        //        return ViewState["StationID"].ToString();
        //    }
        //    set
        //    {
        //        ViewState["StationID"] = value;
        //    }
        //}
        private string IsCopyAllButon
        {
            get
            {
                return ViewState["IsCopyAllButon"].ToString();
            }
            set
            {
                ViewState["IsCopyAllButon"] = value;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                // add by dylan 20151030 for u275.1 
                this.grdPopSearchStaff.PageSize = this.GridViewPageDefaultSize();

                this.tnNo = Request.QueryString["txt_TNNO"].ToString();
                this.transNo = Request.QueryString["txt_TransNo"].ToString();
                //remove by gordon 20151022 U247
                //this.StationID = Request.QueryString["txt_StationID"].ToString();
                this.IsCopyAllButon = Request.QueryString["IsCopyAllButon"].ToString();
                string callbypage = Request.QueryString["CallByPage"].ToString();
                if (!string.IsNullOrEmpty(callbypage))
                {
                    if (callbypage == "1")
                    {
                        this.tnNo = this.transNo = "ByClientEvent";
                    }
                }
                SetLanguage();
                BindData();
                //Add Date: 2015-08-18 Nathan
                btnCopyAllPossession.Attributes.Add("OnClick", "GetPossession()");
                btnCopyProtectionOnly.Attributes.Add("OnClick", "Only()");
                btnCancel.Attributes.Add("OnClick", "WClose()");
                //Add Date: 2015-08-18 Nathan
            }
        }

        private void SetLanguage()
        {
            //this.lblStaffType.Text = this.GetLabel("SOM_SearchStaffType", true); //Modify by zengshunbo issue 1049
            //this.lblStaffID.Text = this.GetLabel("SOM_SearchStaffID", true); //Modify by zengshunbo issue 1049
            //this.lblStaffName.Text = this.GetLabel("SOM_SearchStaffName", true); //Modify by zengshunbo issue 1049
            //this.lblContactNo.Text = this.GetLabel("COM_ContactNo", true);
            //this.lblEmail.Text = this.GetLabel("COM_Email", true);
            //this.lblDepartmentCompany.Text = this.GetLabel("SOM_DepartmentCompany", true); //huangyao 20090209: new change
            //this.lblDepartmentCompany.Text = this.GetLabel("SOM_Company", true);  //huangyao 20090209: new change
            //this.btnSearch.Value = this.GetLabel("COM_Search");
            //this.btnColse.Value = this.GetLabel("COM_Close");
            //Add Date: 2015-08-18 Nathan
            btnCopyAllPossession.Text = this.GetLabel("SOM_CopyAllPossession");
            btnCopyProtectionOnly.Text = this.GetLabel("SOM_CopyProtectionOnly");
            btnCancel.Text = this.GetLabel("SOM_Cancel");
            //Add Date: 2015-08-18 Nathan
        }

        private void ChangeLanguage_Click(object sender, System.EventArgs e)
        {
            SetLanguage();
        }

        #endregion

        #region Data Grid Bind

        //private void btnSearch_ServerClick(object sender, EventArgs e)
        //{
        //    BindData();
        //}

        private void BindData()
        {
            DataTable dataTable;
            dataTable = MTRC.ODMS.DAL.SOM.Event.StationEventAdmRegDa.GetEngineeringWorkInfo(this.ODMUser.LocationID.ToString(), this.tnNo, this.transNo).Tables[0];

            for (int i = dataTable.Rows.Count - 1; i >= 0; i--)
            {
                if (!dataTable.Rows[i]["isStation"].ToString().Equals("Y"))
                {
                    dataTable.Rows.RemoveAt(i);
                }
            }
            DataView dataView = dataTable.DefaultView;
            this.grdPopSearchStaff.GetLabelFunction = new APJ.Web.UI.WebControls.GetLabel(this.GetLabel);
            this.grdPopSearchStaff.DataSource = dataTable.DefaultView;
            this.grdPopSearchStaff.DataBind();
            dataView = null;
            dataTable = null;
        }
        private void grdPopSearchStaff_NeedDataBind()
        {
            BindData();
        }

        protected void grdPopSearchStaff_OnRowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.DataRow)
            {
               
                e.Row.Attributes.Add("onmouseover", "this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#eaffd9';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor");
              
                //Add Date: 2015-08-18 Nathan
                //e.Row.Attributes.Add("OnClick", "SetTNNo('" + DataBinder.Eval(e.Row.DataItem, "GrantTN").ToString()
                //       + "','" + DataBinder.Eval(e.Row.DataItem, "GrantMasTrxnNo").ToString()
                //       + "', '" +DataBinder.Eval(e.Row.DataItem, "JobNature").ToString()
                //       + "', '" + DataBinder.Eval(e.Row.DataItem, "JobLocation").ToString()
                //       + "', '" + DataBinder.Eval(e.Row.DataItem, "JobProtection").ToString()
                //       + "', '" + this.IsCopyAllButon
                //       + "',this);");
                //Add Date: 2015-08-18 Nathan

                //add by Tim 2016-03-11 U59
                //e.Row.Attributes.Add("OnClick", "setWorkInfor('" + APJ.Util.Utility.ScriptStrHandler(DataBinder.Eval(e.Row.DataItem, "GrantTN").ToString())
                //      + "','" + DataBinder.Eval(e.Row.DataItem, "GrantMasTrxnNo").ToString()
                //      + "', '" + DataBinder.Eval(e.Row.DataItem, "JobNature").ToString()
                //      + "', '" + DataBinder.Eval(e.Row.DataItem, "JobLocation").ToString()
                //      + "', '" + DataBinder.Eval(e.Row.DataItem, "JobProtection").ToString()
                //      + "', '" + this.IsCopyAllButon
                //      + "');");
                e.Row.Attributes.Add("OnClick", "setWorkInfor('" + APJ.Util.Utility.ScriptStrHandler(DataBinder.Eval(e.Row.DataItem, "GrantTN").ToString())
                        + "','" + APJ.Util.Utility.ScriptStrHandlerOne(DataBinder.Eval(e.Row.DataItem, "GrantMasTrxnNo").ToString())
                        + "', '" + APJ.Util.Utility.ScriptStrHandlerOne(DataBinder.Eval(e.Row.DataItem, "JobNature").ToString())
                        + "', '" + APJ.Util.Utility.ScriptStrHandlerOne(DataBinder.Eval(e.Row.DataItem, "JobLocation").ToString())
                        + "', '" + APJ.Util.Utility.ScriptStrHandlerOne(DataBinder.Eval(e.Row.DataItem, "JobProtection").ToString())
                        + "', '" + this.IsCopyAllButon
                        + "');");
                
            }
        }
        #endregion

        #region Web Form Designer generated code

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            this.ChangeLanguage += new MTRC.ODMS.Web.BasePage.ChangeLanguageEventHandler(this.ChangeLanguage_Click);
            //this.btnSearch.ServerClick += new EventHandler(btnSearch_ServerClick);
            this.grdPopSearchStaff.NeedDataBind += new APJ.Web.UI.WebControls.CommonGridView.NeedDataBindHandler(grdPopSearchStaff_NeedDataBind);
        }

        #endregion

      
    }
}
